package com.xinfan.io.fileoutputstream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;

/**
 * @Author xin
 * @Date 2022/6/8 15:32
 * @Version 1.0
 */
public class CopyImage {
    public static void main(String[] args) {
        String source = "g:\\桌面\\11111.png";
        String des = "g:\\桌面\\3322.png";
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        //int readData = 0;
        byte[] b = new byte[1024];
        int len = 0;

        try {
            fileInputStream = new FileInputStream(source);
            fileOutputStream = new FileOutputStream(des);
            while ((len = fileInputStream.read(b)) != -1) {
                //byte[] bytes = Arrays.copyOf(b, len);
                fileOutputStream.write(b,0,len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
                if (fileOutputStream != null) {
                    fileOutputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
